package com.eorchis.module.classnotice.service.impl;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.hibernate.lob.SerializableBlob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eorchis.components.attachment.dao.IAttachmentDao;
import com.eorchis.components.attachment.domain.Attachment;
import com.eorchis.core.basedao.dao.IDaoSupport;
import com.eorchis.core.basedao.entity.IBaseEntity;
import com.eorchis.core.service.impl.AbstractBaseService;
import com.eorchis.core.ui.commond.ICommond;
import com.eorchis.module.classnotice.dao.IClassNoticeDao;
import com.eorchis.module.classnotice.domain.ClassNotice;
import com.eorchis.module.classnotice.querybean.ClassNoticeQueryBean;
import com.eorchis.module.classnotice.service.IClassNoticeService;
import com.eorchis.module.classnotice.ui.commond.ClassNoticeQueryCommond;
import com.eorchis.module.classnotice.ui.commond.ClassNoticeValidCommond;

/**
 * Title: ClassNoticeServiceImpl<br>
 * Description: 入学通知管理业务接口实现<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author Max
 * @createDate 2014-12-12
 * @version $Revision$
 */
// 声明本类为Server实现类，声明bean名称
@Service(value = "com.eorchis.module.classnotice.service.impl.ClassNoticeServiceImpl")
public class ClassNoticeServiceImpl 
			extends AbstractBaseService 
		implements IClassNoticeService {
		
	@Autowired
	@Qualifier("com.eorchis.module.classnotice.dao.impl.ClassNoticeDaoImpl")
	private IClassNoticeDao classNoticeDao;
	
	@Autowired
	@Qualifier("com.eorchis.components.fileupload.dao.impl.AttachmentDaoImpl")
	private IAttachmentDao attachmentDao;
		

	public IDaoSupport getDaoSupport() {
		return classNoticeDao;
	}
	@SuppressWarnings("unchecked")
	public ClassNoticeValidCommond toCommond(IBaseEntity entity) {
		return new ClassNoticeValidCommond((ClassNotice)entity);
	}
	/**
	 * 查询班级入学通知
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-12
	 */
	@Override
	public List<ClassNoticeQueryBean> findClassNoticeAllList(ClassNoticeQueryCommond 
			qCommond) throws Exception {
		return classNoticeDao.findClassNoticeAllList(qCommond);
	}
	
	/**
	 * 删除班级入学通知
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-12
	 */
	@Override
	public void deleteNotic(ClassNoticeQueryCommond qCommond) throws Exception {
		//查询专题信息
		ClassNotice cn=classNoticeDao.find(ClassNotice.class, qCommond.getSearchNoticeId());
		//删除附件表信息
		attachmentDao.delete(Attachment.class, new String[] {cn.getAttachmentId()});
		//删除通知表
		classNoticeDao.delete(ClassNotice.class, new String [] {cn.getNoticeId()});
		
	}
	@Override
	public byte[] getFileBytes(ClassNoticeQueryCommond qCommond) throws Exception {
		return classNoticeDao.getFileblob(qCommond);
	}
	@Override
	public String getFileName(ClassNoticeQueryCommond qCommond)
			throws Exception {
		return classNoticeDao.getFileName(qCommond);
	}
}
